package 蓝桥算法;

public class day11 {

  public int[] getnext(String s){
      int len=s.length();
      char[] a=s.toCharArray();
      int[] next=new int[s.length()];
      for(int i=1,j=0;i<s.length();i++){
          while(j>0&&a[i]!=a[j]){
              j=next[j-1];//一直不等则j一直回退
          }
          if(a[i]==a[j]){
              j++;
          }
              next[i]=j;
      }
      return next;
  }
    public static void main(String[] args) {
        String s="aabaaf";
        day11 a=new day11();
        int[] x=a.getnext(s);
        for (int i = 0; i < x.length; i++) {
            System.out.println(x[i]);
        }
    }
}
